From: Florian Müllner Date: Thu, 4 Aug 2022 14:47:22 +0000 (+0200) Subject: status/network: Track device sections as device sections X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~461^2^2~131 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=58d29f95a76a8bd96af0bdb2e4d744217df10319;p=gnome-shell.git status/network: Track device sections as device sections The _devices property is another case of overloading the "device" term. Fun fact: this._devices[device._delegate.category].devices uses three different meanings of "device" (section, NM.Device, item). The devices array in sections won't be around for much longer, but the property that tracks the sections is worth renaming. While at it, use a map instead of a plain object, which has a guaranteed order when iterating (which will come in handy later). Part-of: --- diff --git a/js/ui/status/network.js b/js/ui/status/network.js index 05913d179..c36be957f 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -1784,7 +1784,7 @@ class Indicator extends PanelMenu.SystemIndicator { this._notification = null; this._nmDevices = []; - this._devices = { }; + this._deviceSections = new Map(); const categories = [ NMConnectionCategory.WIRED, @@ -1792,8 +1792,8 @@ class Indicator extends PanelMenu.SystemIndicator { NMConnectionCategory.WWAN, ]; for (let category of categories) { - this._devices[category] = new DeviceCategory(category); - this.menu.addMenuItem(this._devices[category]); + this._deviceSections.set(category, new DeviceCategory(category)); + this.menu.addMenuItem(this._deviceSections.get(category)); } this._vpnSection = new NMVpnSection(this._client); @@ -1924,10 +1924,10 @@ class Indicator extends PanelMenu.SystemIndicator { wrapper.connectObject('activation-failed', this._onActivationFailed.bind(this), this); - let section = this._devices[wrapper.category].section; + const {section} = this._deviceSections.get(wrapper.category); section.addMenuItem(wrapper.item); - let devices = this._devices[wrapper.category].devices; + const {devices} = this._deviceSections.get(wrapper.category); devices.push(wrapper); } @@ -1951,7 +1951,7 @@ class Indicator extends PanelMenu.SystemIndicator { wrapper.disconnectObject(this); wrapper.destroy(); - let devices = this._devices[wrapper.category].devices; + const {devices} = this._deviceSections.get(wrapper.category); let pos = devices.indexOf(wrapper); devices.splice(pos, 1); } @@ -2058,7 +2058,7 @@ class Indicator extends PanelMenu.SystemIndicator { if (section == NMConnectionCategory.VPN) { this._vpnSection.removeConnection(connection); } else { - let devices = this._devices[section].devices; + const {devices} = this._deviceSections.get(section); for (let i = 0; i < devices.length; i++) { if (devices[i] instanceof NMConnectionSection) devices[i].removeConnection(connection); @@ -2081,7 +2081,7 @@ class Indicator extends PanelMenu.SystemIndicator { if (section == NMConnectionCategory.VPN) { this._vpnSection.checkConnection(connection); } else { - let devices = this._devices[section].devices; + const {devices} = this._deviceSections.get(section); devices.forEach(wrapper => { if (wrapper instanceof NMConnectionSection) wrapper.checkConnection(connection);